var 
C       
M
N_m
P_E
D_E
R_R
W
V
E_t_V_tp1_1_minus_sigma
Y
K_m
I_m
D
Pi
R_K
q
mu
sigma_a
a
Z
R
Xi
u
PHI
sigma_z
PF_normalization
C_m
C_n
L
N_n
I_n
K_n
q_n
u_n
util
utilC
utilL
Lambda
alpha1_ex
aux_sigma
R_E     
E_R_E   
E_R_E_squared   
cond_var_R_E    
;

varexo 
//eps_sigma_z     
eps        
eps_sigma   
eps_z           
;

parameters 
siggma   
theta_v
psii
eta
betta
theta_mu
alppha
Psi 
delta_0
delta_1
delta_2
phi_k
phi_p
Pi_bar
nu
rho_r 
rho_pi
rho_y 
log_R_bar 
sigma_a_bar
sigma_sigma_a
rho_a
rho_sigma_a
a_bar
sigma_z_bar
rho_z
V_normalization
sigma_eps_m
subsidy
sigma_sigma_z 
rho_sigma_z   
PF_normalization_bar
b1P
alpha1P
alpha2P             
delta_n_0                     
delta_n_1           
delta_n_2                    
phi_k_n
fixed_homepI
home_capitalI
kuI
ezI                                     
capitalI
alpha1I
uncertainty_shockI
C_n_bar                                                                                                                                 
N_n_bar                                                                 
I_n_bar                                                                 
K_n_bar                                                                 
q_n_bar                                                                 
u_n_bar
W_bar
C_m_bar
C_bar                
C_ss       
M_ss
N_m_ss
P_E_ss
D_E_ss
R_R_ss
W_ss
V_ss
E_t_V_tp1_1_minus_sigma_ss
Y_ss
K_m_ss
I_m_ss
D_ss
Pi_ss
R_K_ss
q_ss
mu_ss
sigma_a_ss
a_ss
Z_ss
R_ss
Xi_ss
u_ss
PHI_ss
sigma_z_ss
PF_normalization_ss
C_m_ss
C_n_ss
L_ss
N_n_ss
I_n_ss
K_n_ss
q_n_ss
u_n_ss
util_ss
utilC_ss
utilL_ss
Lambda_ss
alpha1_ex_ss
aux_sigma_ss
sigma_alpha1_ss
R_E_ss 
E_R_E_ss   
E_R_E_squared_ss  
cond_var_R_E_ss 
;



siggma               = 80;                 
theta_v              = 1501;               
psii                 = 0.95;               
eta                  = 0.525790189389929;  
betta                = 0.994;              
theta_mu             = 6;                  
alppha               = 0.159836519114688;  
Psi                  = 0.2;                
delta_0              = 0.025;              
delta_1              = 0.0310362173038229; 
delta_2              = 0.00031;            
phi_k                = 2.0901;             
phi_p                = 100;                
Pi_bar               = 1.005;              
nu                   = 0.9;                
rho_r                = 0;                  
rho_pi               = 1.5;                
rho_y                = 0.2;                
log_R_bar            = 0.0110056138366019; 
sigma_a_bar          = 0.0026251;          
sigma_sigma_a        = 0.0025022;          
rho_a                = 0.93564;            
rho_sigma_a          = 0.3340215;          
a_bar                = 1;                  
sigma_z_bar          = 0.0012857;          
rho_z                = 0.98793;            
V_normalization      = 0.00575868641958297;
sigma_eps_m          = 0;                  
subsidy              = 1;                  
sigma_sigma_z        = 0.42;               
rho_sigma_z          = 0.63;               
PF_normalization_bar = 0.851807876825313;  
b1P                  = 0.5;                
alpha1P              = 0.456844794526875;  
alpha2P              = 0;                  
delta_n_0            = 0.025;              
delta_n_1            = 0.0310362173038229; 
delta_n_2            = 0.00031;            
phi_k_n              = 2.0901;             
fixed_homepI         = 1;                  
home_capitalI        = 0;                  
kuI                  = 0;                  
ezI                  = 1;                  
alpha1I              = 0;                  
uncertainty_shockI   = 1;                  
capitalI             = 1;                  
C_n_bar              = 0.19;               
N_n_bar              = 0.19;               
I_n_bar              = 0;                  
K_n_bar              = 1;                  
q_n_bar              = 1;                  
u_n_bar              = 1;                  
W_bar                = 2.5459499420767;    
C_m_bar              = 0.87125;            
C_bar                = 0.439805497509817;  
C_ss                       = 0.439805497509817;  
M_ss                       = 0.994;              
N_m_ss                     = 0.33;               
P_E_ss                     = 0.542809999999966;  
D_E_ss                     = 0.00327651911468792;
R_R_ss                     = 1.00603621730382;   
W_ss                       = 2.5459499420767;    
V_ss                       = 1;                  
E_t_V_tp1_1_minus_sigma_ss = 1;                  
Y_ss                       = 1;                  
K_m_ss                     = 5.15;               
I_m_ss                     = 0.12875;            
D_ss                       = 0.0310865191146874; 
Pi_ss                      = 1.005;              
R_K_ss                     = 0.0310362173038229; 
q_ss                       = 1;                  
mu_ss                      = 1.2;                
sigma_a_ss                 = 0.0026251;          
a_ss                       = 1;                  
Z_ss                       = 1;                  
R_ss                       = 1.01106639839034;   
Xi_ss                      = 0.833333333333333;  
u_ss                       = 1;                  
PHI_ss                     = 1;                  
sigma_z_ss                 = 0.0012857;          
PF_normalization_ss        = 0.851807876825313;  
C_m_ss                     = 0.87125;            
C_n_ss                     = 0.19;               
L_ss                       = 0.48;               
N_n_ss                     = 0.19;               
I_n_ss                     = 0;                  
K_n_ss                     = 1;                  
q_n_ss                     = 1;                  
u_n_ss                     = 1;                  
util_ss                    = 0.458428299092145;  
utilC_ss                   = 0.54805386373321;   
utilL_ss                   = 0.452898326855798;  
Lambda_ss                  = 0.404303272721647;  
alpha1_ex_ss               = 0;                  
aux_sigma_ss               = 0.0026251;          
sigma_alpha1_ss            = 0.0026251;          
R_E_ss                     = 1.00603621730382;   
E_R_E_ss                   = 1.00603621730382;   
E_R_E_squared_ss           = 1.01210887052699;   
cond_var_R_E_ss            = 0;                  

model;

V = ezI*((V_normalization*a*(util^((1-siggma)/theta_v)) + betta*(E_t_V_tp1_1_minus_sigma)^(1/theta_v))^(theta_v/(1-siggma)))
+ (1-ezI)*(V_normalization*a*(util^(1-siggma))/(1-siggma) + betta*V(+1));

M = ezI*(betta*(a/a(-1))*((util/util(-1))^((1-siggma)/theta_v - 1))*(utilC/utilC(-1))*((C_m*C(-1)/(C_m(-1)*C))^(b1P-1))*(((V^(1-siggma))/E_t_V_tp1_1_minus_sigma(-1))^(1-1/theta_v)))
+ (1-ezI)*betta*(a(+1)/a)*(utilC(+1)/utilC)^(1-siggma)*(C/C(+1));

E_t_V_tp1_1_minus_sigma=V(+1)^(1-siggma);

0 = capitalI*(- (C_m + I_n +P_E+1/R_R*nu*K_m) + W*N_m+(D_E+P_E)+nu*K_m(-1))
+ (1-capitalI)*(- C_m  + Y);

W =(utilL/utilC)*(1/(alpha1P*exp(alpha1_ex)))*((C_m/C)^(1-b1P));

P_E=M(+1)*(D_E(+1)+P_E(+1));

1=R_R*M(+1);

Y=exp(PF_normalization)*(u*K_m(-1))^alppha*(Z*N_m)^(1-alppha)-Psi;

K_m= capitalI*((1-(delta_0 + delta_1*(u-1)+delta_2/2*(u-1)^2)-phi_k/2*(I_m/K_m(-1)-delta_0)^2)*K_m(-1)+I_m)
+(1-capitalI);

D= Y-W*N_m-I_m-phi_p/2*(Pi/Pi_bar-1)^2*Y;

W*N_m=(1-alppha)*Xi*exp(PF_normalization)*(u*K_m(-1))^alppha*(Z*N_m)^(1-alppha);

R_K*(u*K_m(-1))=alppha*Xi*exp(PF_normalization)*(u*K_m(-1))^alppha*(Z*N_m)^(1-alppha);

0 = capitalI*(kuI*(-q*(delta_1+delta_2*(u-1))*u*K_m(-1)+ alppha*Xi*exp(PF_normalization)*(u*K_m(-1))^alppha*(Z*N_m)^(1-alppha))+ (1-kuI)*(u - 1))
+(1-capitalI)*(u - 1);

phi_p*(Pi/Pi_bar-1)*(Pi/Pi_bar)=(1-theta_mu)+theta_mu*Xi+phi_p*
M(+1)*(Y(+1)/Y)*(Pi(+1)/Pi_bar-1)*(Pi(+1)/Pi_bar);

q= capitalI*(M(+1)*(u(+1)*R_K(+1)+q(+1)*(1-(delta_0 + delta_1*(u(+1)-1)+delta_2/2*(u(+1)-1)^2)-phi_k/2*(I_m(+1)/K_m-delta_0)^2 +phi_k*(I_m(+1)/K_m-delta_0)*(I_m(+1)/K_m))))
+(1-capitalI);

1/q=capitalI*(1-phi_k*(I_m/K_m(-1)-delta_0))
+(1-capitalI)*(1/q - I_m);

D_E=capitalI*(D-nu*(K_m(-1)-1/R_R*K_m))
+(1-capitalI)*D;

log(R)=rho_r*log(R(-1))+(1-rho_r)*(log_R_bar+rho_pi*(log(Pi)-log(Pi_bar))+rho_y*(log(Y)-log(Y(-1))));//+sigma_eps_m*eps;

1=betta*(a(+1)/a)*((util(+1)/util)^((1-siggma)/theta_v - 1))*(utilC(+1)/utilC)*((C_m(+1)*C/(C_m*C(+1)))^(b1P-1))*(((V(+1)^(1-siggma))/E_t_V_tp1_1_minus_sigma)^(1-1/theta_v))*(R/Pi(+1));

mu=1/Xi;

PHI=1+phi_p/2*(Pi/Pi_bar-1)^2*Y;

a=(1-rho_a)*a_bar+rho_a*a(-1)+sigma_a(-1)*eps*uncertainty_shockI;

sigma_a=(1-rho_sigma_a)*sigma_a_bar+rho_sigma_a*sigma_a(-1)+sigma_sigma_a*eps_sigma*uncertainty_shockI;

Z=(1-rho_z)*1+rho_z*Z(-1)-sigma_z_bar*eps_z;

PF_normalization = rho_z*PF_normalization(-1) + (1-rho_z)*PF_normalization_bar;

sigma_z = (1-rho_sigma_z)*sigma_z_bar + rho_sigma_z*sigma_z(-1);

util = C^eta*(L^(1-eta));

utilC = eta*(C^(eta-1))*(L^(1-eta));

utilL = (1-eta)*(C^eta)*(L^-eta);

C = ((alpha1P*exp(alpha1_ex))*(C_m^b1P) + (1-(alpha1P*exp(alpha1_ex)))*(C_n^b1P))^(1/b1P) ;

L = 1 - N_m - N_n;

C_n = (1-fixed_homepI)*capitalI*((u_n*K_n(-1))^alpha2P)*(N_n^(1-alpha2P))
+ (1-fixed_homepI)*(1-capitalI)*(N_n^(1-alpha2P))
+ fixed_homepI*(C_n_bar);

K_n = (1-fixed_homepI)*home_capitalI*((1-(delta_n_0 + delta_n_1*(u_n-1)+delta_n_2/2*(u_n-1)^2)-phi_k_n/2*(I_n/K_n(-1)-delta_n_0)^2)*K_n(-1)+I_n)
+ (fixed_homepI + (1-fixed_homepI)*(1-home_capitalI))*K_n_bar;

0   = kuI*(1-fixed_homepI)*home_capitalI*(- q_n*u_n*(delta_n_1+delta_n_2*(u_n-1)) + alpha2P*((1-(alpha1P*exp(alpha1_ex)))/(alpha1P*exp(alpha1_ex)))*(C_n/K_n(-1))*((C_n/C_m)^(b1P-1)))
+ (fixed_homepI + (1-fixed_homepI)*(1-home_capitalI))*(u_n - u_n_bar);

0 = (1-fixed_homepI)*home_capitalI*(- q_n + q_n(+1)*M(+1)*(u_n(+1)*(delta_n_1+delta_n_2*(u_n(+1)-1)) + (1-(delta_n_0 + delta_n_1*(u_n(+1)-1)+delta_n_2/2*(u_n(+1)-1)^2)-phi_k_n/2*(I_n(+1)/K_n-delta_n_0)^2 +phi_k_n*(I_n(+1)/K_n-delta_n_0)*(I_n(+1)/K_n))))
+ (fixed_homepI + (1-fixed_homepI)*(1-home_capitalI))*(I_n - I_n_bar);

0 = (1-fixed_homepI)*((1-(alpha1P*exp(alpha1_ex)))*(1-alpha2P)*((C_n/C)^(b1P - 1))*(C_n/N_n) - utilL/utilC)
+ fixed_homepI*(N_n - N_n_bar);

0 = (1-fixed_homepI)*home_capitalI*(- 1/q_n + 1-phi_k_n*(I_n/K_n(-1)-delta_n_0))
+ (fixed_homepI + (1-fixed_homepI)*(1-home_capitalI))*(q_n - q_n_bar);

Lambda = ezI*((V/util)^(1-(1-siggma)/theta_v)*utilC*(alpha1P*exp(alpha1_ex))*(C_m/C)^(b1P-1)*a)
+(1-ezI)*(util^-siggma)*utilC;

alpha1_ex = -(aux_sigma - sigma_a_bar);

aux_sigma  = ((1-rho_sigma_a)*sigma_a_bar+rho_sigma_a*aux_sigma(-1)+0.01*eps)*alpha1I*(1-uncertainty_shockI) 
+ ((1-rho_sigma_a)*sigma_a_bar+rho_sigma_a*aux_sigma(-1)+0.0025022*4*eps_sigma*uncertainty_shockI*alpha1I)*uncertainty_shockI*alpha1I
+ sigma_a_bar*(1-alpha1I);

R_E=(D_E + P_E)/P_E(-1);

E_R_E=R_E(+1);

E_R_E_squared=R_E(+1)^2;

cond_var_R_E=E_R_E_squared-E_R_E^2;

end;

initval;
C                           =   C_ss;                        
N_m                         =   N_m_ss;                        
W                           =   W_ss;                        
V                           =   V_ss;                        
E_t_V_tp1_1_minus_sigma     =   E_t_V_tp1_1_minus_sigma_ss;  
Y                           =   Y_ss;                        
K_m                         =   K_m_ss;                        
I_m                         =   I_m_ss;                        
Pi                          =   Pi_ss;                       
R_K                         =   R_K_ss;                      
q                           =   q_ss;                        
mu                          =   mu_ss;                       
sigma_a                     =   sigma_a_ss;                  
a                           =   a_ss;                        
Z                           =   Z_ss;                        
R                           =   R_ss;                        
Xi                          =   Xi_ss;                       
u                           =   u_ss;                        
PHI                         =   PHI_ss;                      
D                           =   D_ss;                        
P_E                         =   P_E_ss;                      
D_E                         =   D_E_ss;                      
R_R                         =   R_R_ss;                      
M                           =   M_ss;
PF_normalization            =   PF_normalization_ss;
sigma_z                     =   sigma_z_ss;
C_m                         =   C_m_ss;
C_n                         =   C_n_ss;
L                           =   L_ss;
N_n                         =   N_n_ss;
I_n                         =   I_n_ss;
K_n                         =   K_n_ss;
q_n                         =   q_n_ss;
u_n                         =   u_n_ss;
util                        =   util_ss;
utilC                       =   utilC_ss;
utilL                       =   utilL_ss;
Lambda                      =   Lambda_ss;
alpha1_ex                   =   alpha1_ex_ss;
aux_sigma                   =   sigma_a_ss;
R_E                         =   R_E_ss;   
E_R_E                       =   E_R_E_ss;
E_R_E_squared               =   E_R_E_squared_ss;   
cond_var_R_E                =   cond_var_R_E_ss;   

end;

//---------------------------------------------------------------------
// here you need to enter **variances**
//---------------------------------------------------------------------

vcov = [1 0 0;
0 1 0
0 0 1];

